{
 "metadata": {
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.9.0-final"
  },
  "orig_nbformat": 2,
  "kernelspec": {
   "name": "python37764bit5d211478a4cf4a3d93a2c891f6a9207d",
   "display_name": "Python 3.7.7 64-bit"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2,
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [
    {
     "output_type": "execute_result",
     "data": {
      "text/plain": [
       "'Resluts of the 2020 Referendum'"
      ]
     },
     "metadata": {},
     "execution_count": 1
    }
   ],
   "source": [
    "'''\n",
    "1.使用f 或 F 字符串\n",
    "'''\n",
    "\n",
    "year = 2020\n",
    "event = \"Referendum\"\n",
    "f'Resluts of the {year} {event}'"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [
    {
     "output_type": "execute_result",
     "data": {
      "text/plain": [
       "' 42572654 Yes votes 49.67%'"
      ]
     },
     "metadata": {},
     "execution_count": 2
    }
   ],
   "source": [
    "'''\n",
    "2.str.format()\n",
    "'''\n",
    "yes_vote = 42_572_654\n",
    "no_vote = 43_132_495\n",
    "percentage= yes_vote / (yes_vote + no_vote)\n",
    "'{:-9} Yes votes {:2.2%}'.format(yes_vote, percentage)\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [
    {
     "output_type": "execute_result",
     "data": {
      "text/plain": [
       "'Hello, Python.'"
      ]
     },
     "metadata": {},
     "execution_count": 3
    }
   ],
   "source": [
    "'''\n",
    "str():返回人类可读的\n",
    "repr():返回解释器可读的\n",
    "\n",
    "1. 参数都是字符串时，2个函数没有区别\n",
    "'''\n",
    "s = 'Hello, Python.'\n",
    "str(s)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [
    {
     "output_type": "execute_result",
     "data": {
      "text/plain": [
       "\"'Hello, Python.'\""
      ]
     },
     "metadata": {},
     "execution_count": 4
    }
   ],
   "source": [
    "repr(s)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {},
   "outputs": [
    {
     "output_type": "execute_result",
     "data": {
      "text/plain": [
       "'0.14285714285714285'"
      ]
     },
     "metadata": {},
     "execution_count": 6
    }
   ],
   "source": [
    "str(1/7)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {},
   "outputs": [
    {
     "output_type": "stream",
     "name": "stdout",
     "text": [
      "the value of x is 32.5, and y is 40000...\n"
     ]
    }
   ],
   "source": [
    "x = 10 * 3.25\n",
    "y = 200 * 200\n",
    "s = \"the value of x is \" + repr(x) + ', and y is ' + repr(y) + '...'\n",
    "print(s)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {},
   "outputs": [
    {
     "output_type": "stream",
     "name": "stdout",
     "text": [
      "'hello world\\n'\n"
     ]
    }
   ],
   "source": [
    "hello = 'hello world\\n'\n",
    "hellos = repr(hello)\n",
    "print(hellos)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {},
   "outputs": [
    {
     "output_type": "execute_result",
     "data": {
      "text/plain": [
       "\"(32.5, 40000, ('spam', 'eggs'))\""
      ]
     },
     "metadata": {},
     "execution_count": 9
    }
   ],
   "source": [
    "repr((x, y, ('spam','eggs')))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ]
}